# -*- coding: utf-8 -*-
import unittest

from crm.base.crm_use_browser import UseBrowser
from crm.db.customerassgin.dbcrm_customer import DbCustomerAssign
from crm.util.yaml_operation import YamlOperation
from crm.webpage.customerassign.customerssign_page import CustomerAssignPage
from crm.webpage.login_page import LoginPage


class TestCustomerAssign(unittest.TestCase):

    # 前置条件
    def setUp(self) -> None:
        self.lp = LoginPage()
        self.lp.login(self.lp.exl.get_cell(1, 2), self.lp.exl.get_cell(1, 3))
        self.cap = CustomerAssignPage()
        self.yo = YamlOperation()
        self.db_ca=DbCustomerAssign()

    # 客户分配，勾选一个
    def test_customerassign_1_one(self):
        # 进入客户分配
        self.cap.customer_assign()
        self.cap.customer_assign_one(self.cap.exl.get_cell(1, 1))
        self.assertEqual(self.cap.exl.get_cell(1, 4),self.cap.get_customer_assign_one())
        # 数据库查询数据
        db_data = self.db_ca.sec_customer_info(self.cap.exl.get_cell(1, 1),
                                               self.cap.exl.get_cell(1, 2))
        self.assertIsNotNone(db_data)


    def tearDown(self) -> None:
        self.db_ca.put_customer_idnull(self.cap.exl.get_cell(1, 1))
        UseBrowser.driver.quit()

if __name__ == '__main__':
    unittest.main()
    # suite = unittest.TestSuite()  # 实例化
    # test_custass = unittest.TestLoader().loadTestsFromTestCase(TestCustomerAssign)
    # test_custass_all = unittest.TestLoader().loadTestsFromTestCase(TestCustomerAssignAll)
    #
    # suite.addTests([test_custass,test_custass_all])
    #
    # c_time = time.strftime('%Y-%m-%d_%H_%M', time.localtime())
    # with open('../../report/report' + c_time + '.html', 'wb+') as fp:
    #     runner = HwTestReport.HTMLTestReport(stream=fp, verbosity=2, title='测试结果', description='CRM房地产客户关系管理系统,客户分配')
    #     runner.run(suite)